package com.orange.delivery.application;

import java.util.List;
import java.util.Map;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import com.orange.delivery.model.MarketBean;
import com.orange.delivery.technicalservice.exception.InvalidMarketException;
import com.orange.delivery.technicalservice.exception.InvalidQueryException;
import com.orange.delivery.technicalservice.exception.NotFoundException;
import com.orange.delivery.technicalservice.tool.MultiValuedMap;

/**
 * application interface for market component
 * 
 * @author Clara
 */
public interface ManageMarket {

	/**
	 * Find all markets
	 * 
	 * @return Map of markets
	 * @throws NotFoundException
	 *             if no market found
	 */
	Map<Integer, MarketBean> findAllMarkets() throws NotFoundException;

	/**
	 * find market which name contains parameter
	 * 
	 * @param name
	 *            String used to search for market names
	 * @return List of market beans
	 * @throws NotFoundException
	 *             if no market found
	 */
	List<MarketBean> findMarketByName(String name) throws NotFoundException;

	/**
	 * count market which name contains parameter
	 * 
	 * @param name
	 *            String used to search for market names
	 * @return the number of market beans
	 * @throws NotFoundException
	 *             if no market found
	 */
	long countMarketByName(String name) throws NotFoundException;

	/**
	 * find market which name contains parameter. The result is paginated
	 * 
	 * @param pageInfo
	 *            information on the requested page
	 * @param name
	 *            String used to search for market names
	 * @return List of market beans
	 * @throws NotFoundException
	 *             if no market found
	 */
	Page<MarketBean> findMarketByName(Pageable pageInfo, String name) throws NotFoundException;

	/**
	 * Create market
	 * 
	 * @param MarketBean
	 *            a market
	 * @return the id of the created market
	 * @throws InvalidMarketException
	 *             if market already exists
	 */
	Integer createMarket(MarketBean market) throws InvalidMarketException;

	/**
	 * Modify market
	 * 
	 * @param MarketBean
	 *            a market
	 * @throws InvalidMarketException
	 *             if market update fails
	 * @throws NotFoundException
	 *             if market does not exist
	 */
	void modifyMarket(MarketBean market) throws InvalidMarketException, NotFoundException;

	/**
	 * Delete market
	 * 
	 * @param idMarket
	 *            market id
	 * @throws InvalidMarketException
	 *             if market deletion fails
	 */
	void deleteMarket(int idMarket) throws InvalidMarketException;

	/**
	 * Consult market
	 * 
	 * @param idMarket
	 *            market id
	 * @throws NotFoundException
	 *             if market does not exist
	 */
	MarketBean consultMarket(int idMarket) throws InvalidMarketException, NotFoundException;

	/**
	 * Obtain a page of markets matching criterias
	 * 
	 * @param pageInfo
	 *            informations on the requested page
	 * @param criteria
	 *            a Map of criterias
	 * @return the requested page
	 * @throws NotFoundException
	 * @throws InvalidQueryException
	 */
	Page<MarketBean> findMarketByCriteria(Pageable pageInfo, MultiValuedMap<String, String> criteria) throws NotFoundException,
			InvalidQueryException;
}